package com.raibaz.atm;

import java.util.List;

import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;

public class AtmLocationListener implements LocationListener {
	
	Location currentLocation = null;
	String currentFrom = "";
	Atm atm;

	public AtmLocationListener(Atm atm) {
		this.atm = atm;
	}
	
	
	public void onLocationChanged(Location location) {
		currentLocation = location;
		currentFrom = "";
		Geocoder gc = new Geocoder(atm.getApplicationContext());
		try {
			List<Address> addresses = gc.getFromLocation(currentLocation.getLatitude(), currentLocation.getLongitude(), 1);
	    	if(!addresses.isEmpty()) {
	    		Address a = addresses.get(0);
	    		for(int i = 0; i < a.getMaxAddressLineIndex(); i++) {
	    			currentFrom += a.getAddressLine(i) + "\n";
	    		}
	    	}
		} catch (Exception e) {
			
		}
	}

	
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub

	}

	
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub

	}

	
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub

	}

}
